<?php


include './debug.php';
include './handler_error.php';


// 设置
error_reporting(E_ALL ^ E_NOTICE);
set_error_handler('errorHandler');
register_shutdown_function('fatalErrorHandler');
date_default_timezone_set('PRC');


/**
 * 获取token
 */
$signature = @$_GET["signature"]; // 签名
$timestamp = @$_GET["timestamp"]; // 时间戳
$echoStr   = @$_GET["echostr"];   // 随机字符
$nonce     = @$_GET["nonce"];     // 随机数
if (!empty($signature) 
    && !empty($timestamp) 
    && !empty($nonce) 
    && !empty($echoStr)) {
    include 'get_token.php';
    exit;
}


/**
 * 接收与响应 普通消息
 */
$dataStr = $GLOBALS['HTTP_RAW_POST_DATA'];
de("\n-----------receive---------\n".$dataStr);
$msgxml = new SimpleXMLElement($dataStr);
if ($msgxml) {
    include_once './send_msg.php';
    include_once './receive_msg.php';
    include_once './event_msg.php';
    include_once './handler_msg.php';
} else {
$msg = '<xml>
<ToUserName><![CDATA['.$msgxml->ToUserName.']]></ToUserName>
<FromUserName><![CDATA['.$msgxml->FormeUserName.']]></FromUserName>
<CreateTime>'.time().'</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content>不支持消息</Content>
</xml>'  ;
echo $msg;
}
exit;

